package com.rosense.server.util;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.rosense.commons.DateUtils;
import com.rosense.commons.LangUtils;
import com.rosense.commons.io.IOUtils;

/**
 * 
 * @author 李岩飞
 * @email eliyanfei@126.com	
 * 2017年12月11日 下午3:53:23
 *
 */
public class EchartsUtils {
	public static String formatTime(long time) {
		return "'"+DateUtils.formatDate(new Date(time), "HH:mm")+"'";
	}
	public static String buildEcharts(String path, Map<String, Object> dataMap) {
		final StringBuilder sb = new StringBuilder();
		try {
			List<String> list = IOUtils.readListFromFile(new File(path), new String[] { "##" });
			for (String s : list) {
				sb.append(s);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		String data = sb.toString();
		dataMap.put("index", new Random().nextInt(100000));
		for (String key : dataMap.keySet()) {
			data = data.replace("$" + key, String.valueOf(dataMap.get(key)));
		}
		return data;
	}
}
